qui(
    function (require, exports, module) {
        Program.Edit = function (options) {
            this.dao = Program.Dao;
            this.task = Program.Task;
            this.config = Program.Config;
            this.options = options || {};
        };
        Com.inherits(Program.Edit, function (options) {
        }).extend({
            init: function () {
                var self = this;
                self.$container = $(".video-edit-form");
                Program.Util.setContainer(self.$container);
                var taskArr = [];
                var param_id = Com.url.getParameter("id");
                var param_from = Com.url.getParameter("from");
                if (param_id != null) {
                    self.dao.cfgName.id = Number(param_id);
                    taskArr.push(self.task.getTargetName(self.dao.cfgName.targetName, {id: param_id}));
                }
                if (param_from != null) {
                    self.dao.cfgName.from = param_from;
                }
                self.remoteCheck = Program.Util.RemoteCheck;
                taskArr.push(self.task.getLiveProgramType(self.dao.cfgName.liveProgramType, function (data) {
                }));
                taskArr.push(self.task.getGradeType(self.dao.cfgName.episodeGradeType));
                taskArr.push(self.task.getLegoChannelType(self.dao.cfgName.category_use));
                taskArr.push(self.task.getLiveTmpOtherType(self.dao.cfgName.live_temp_other));
                var fatherId = Com.url.getParameter("fatherId");
                if (EpgWeb.Plugin.Validate.checkNum(fatherId)) {
                    self.dao.channelId = Number(fatherId);
                    taskArr.push(self.task.getChannel(self.dao.cfgName.getChannel, {id: fatherId}));
                }
                $.each(taskArr, function (index, element) {
                    EpgWeb.ajaxQueue.push(element.regName, element.options);
                })
                EpgWeb.ajaxQueue.afterLoadComplete(function () {
                    $('div[name=multiAddDiv]').addndel({
                        rowClass: 'control-group'
                    })
                    Program.Util.imageCrop($('#AlbumEditScreenCorp'));
                    self.initEditForm();
                })
                EpgWeb.ajaxQueue.startLoad();
            },
            initEditForm: function () {
                $("form[role=form]").submit(function () {
                    return false;
                })
                var self = this;

                self.initDefault();
                if (self.dao.cfgName.id > 0) {
                    self.initByProgramData();
                } else {
                    self.initByChannelData()
                }
                self.initDialog();
                self.initEditPicZone();
                self.initSuggest();
                self.initRelationDataArea()
                self.bindEditEvent();
                self.bindValidate();
            },
            submit: function () {
                console.log("wait to do")
            },
            prepareModel: function () {
                var self = this;
                var entity = {};
                var programEntity = self.dao.getProgram();
                if (programEntity != null) {
                    entity.id = programEntity.id;
                    entity.updateTime = programEntity.updateTime;
                    entity.fatherId = programEntity.fatherId;
                } else {
                    entity.fatherId = $("#fatherId").val();
                }
                entity.pname = $("#pname").val();
                entity.startPlayTime = $("#startPlayTime").val();
                entity.endPlayTime = $("#endPlayTime").val();
                entity.streamStartPlayTime = $("#streamStartPlayTime").val();
                entity.streamEndPlayTime = $("#streamEndPlayTime").val();
                entity.qitanId = $("#qitanId").val();
                entity.waterMarkFlag = $('input:radio[name=waterMarkFlag]:checked').val() == 1 ? true : false;
                entity.subscribe = $("input[name=subscribe]:checked").val();
                entity.allowPopups = $('input:radio[name=dan_mu]:checked').val() == 1 ? true : false;
                entity.freeStatus = $('input:radio[name=freeStatus]:checked').val() == 1 ? true : false;
                entity.vipType = $('select[name=vipType]').val();
                entity.weiboTopic = $("input[name=weiboTopic]").val()
                entity.leftChannel = "";
                entity.audioChannel = "";
                entity.videoPieceLength = 0;
                entity.rightChannel = "";
                entity.description = $("#description").val();
                entity.type = $("#type").val();
                entity.orderBy = 1000;
                entity.allowComment = $("input:radio[name=qitanMarkFlag]:checked").val() == 1 ? true : false;
                entity.logoUrl = "";
                entity.relationList = self.prepareRelation(entity.type);
                entity.qiyiProduct = $("input:radio[name=qiyiProduct]:checked").val() == 1 ? true : false;
                entity.qiyiExclusive = $("input:radio[name=qiyiExclusive]:checked").val() == 1 ? true : false;
                entity.barCode = "";
                entity.episodeGrade = parseInt($("select[name=episodeGrade]").val());
                if (isNaN(entity.episodeGrade)) {
                    entity.episodeGrade = 0;
                }
                entity.daojuEnable = $('input:radio[name=daojuFlag]:checked').val();
                entity.daojuId = $('#daojuId').data('id');
                entity.daojuName = $('#daojuId').val();
                entity.userName = $('header a.name').html();
                entity.chatEnable = $('input:radio[name=chat_enable]:checked').val()
                entity.chatDisplay = $('input:radio[name=chat_display]:checked').val()
                entity.chatRoomId = 0;
                entity.category = "[]";
                entity.uid = Number($("input[name=hidden_uid]").val());
                entity.recommendRate = parseInt($("select[name=recommendRate]").val())
                entity.hot = parseInt($('input:radio[name=hot]:checked').val())
                entity.test = parseInt($('input:radio[name=test]:checked').val())
                if ($("input[name=recommendRemark]").val().length > 0) {
                    entity.recommendRemark = $("input[name=recommendRemark]").val();
                }
                if ($.trim($("input[name=subjectUrl]").val()).length > 0) {
                    entity.subjectUrl = $.trim($("input[name=subjectUrl]").val());
                }
                entity.projectType = $("select[name=project_type_select]").val();
                var channelEntity = self.dao.getChannel();
                if (channelEntity == null) {
                    return
                }
                if (channelEntity.liveType == 2) {
                    entity.categoryCheck = self.makeUpCategory();
                    entity.category = JSON.stringify(entity.categoryCheck);
                }
                return entity;
            },
            prepareRelation: function (entityType) {
                var self = this;
                var relationList = [];
                var channelEntity = self.dao.getChannel();
                if (channelEntity == null) {
                    return
                }
                var _fatherId = channelEntity.id;
                relationList = relationList.concat(self.prepareMultipleItem('#ajaxSuggest', _fatherId, 1, true));
                var item = [];
                if (entityType == 1) {
                    $("input[name=base_3_team]").each(function (index, target) {
                        var $target = $(target)
                        var $targetValue = $target.val();
                        if ($.trim($targetValue).length > 0) {
                            var $scoreValue = $target.parent().find("input[name=base_3_score]").val();
                            if ($.trim($scoreValue).length == 0 || isNaN($scoreValue)) {
                                $scoreValue = 0;
                            } else {
                                $scoreValue = parseInt($scoreValue);
                            }
                            relationList.push({fatherId: _fatherId, "key": $scoreValue, type: 3, "value": $targetValue })
                        }
                    })
                }
                item = self.prepareSingleItem("input[name=playbackSuggest]", _fatherId, 7, true);
                if (item != null) {
                    relationList.push(item);
                }

                item = self.prepareSingleItem("#votePK", _fatherId, 106, true, true);
                if (item != null) {
                    relationList.push(item);
                }
                item = self.prepareSingleItem("#voteRank", _fatherId, 107, true, true);
                if (item != null) {
                    relationList.push(item);
                }

                var keySelect = $("select[name=frontSuggestType]").val();
                if (keySelect == "simple-video") {
                    relationList = relationList.concat(self.prepareMultipleItem('#appendFront_' + keySelect, _fatherId, 5, true));
                } else {
                    item = self.prepareSingleItem('#appendFront_' + keySelect, _fatherId, 5)
                    if (item != null) {
                        relationList.push(item);
                    }
                }
                keySelect = $("select[name=endSuggestType]").val();
                if (keySelect == "simple-video") {
                    relationList = relationList.concat(self.prepareMultipleItem('#appendEnd_' + keySelect, _fatherId, 6, true));
                } else {
                    item = self.prepareSingleItem('#appendEnd_' + keySelect, _fatherId, 6)
                    if (item != null) {
                        relationList.push(item);
                    }
                }
                if (2 == channelEntity.liveType) {
                    var live_tmp_other = $("#live_temp_other").val();
                    if (live_tmp_other.length > 0) {
                        relationList.push({fatherId: _fatherId, key: 0, type: 201, value: live_tmp_other });
                    }
                    // relate passport id
                    var passportId = {uid: $.trim($("input[name=uid_hidden]").val()), nickname: $.trim($("input[name=nickname_hidden]").val())};
                    if (passportId.uid.length > 0 && passportId.nickname.length > 0) {
                        var type301 = {fatherId: _fatherId, key: 0, type: 301, value: passportId.uid };
                        var type302 = {fatherId: _fatherId, key: 0, type: 302, value: passportId.nickname };
                        var dataValid = false;
                        if ($("select[name=passport_select]").val() == "option_uid") {
                            type301.key = 1;
                            dataValid = $.trim($("input[name=passport_uid]").val()) == type301.value;
                            console.log(" passport id 验证失效 " + JSON.stringify(type301) + "  ; " + $.trim($("input[name=passport_uid]").val()));
                        } else if ($("select[name=passport_select]").val() == "option_nickname") {
                            type302.key = 1;
                            dataValid = $.trim($("input[name=passport_nickname]").val()) == type302.value;
                            console.log(" passport id 验证失效 " + JSON.stringify(type302) + "  ; " + $.trim($("input[name=passport_nickname]").val()));
                        }
                        if (dataValid) {
                            relationList.push(type301);
                            relationList.push(type302);
                        } else {
                            console.log(" passport id 验证失效 " + JSON.stringify(type301) + ";" + JSON.stringify(type302));
                        }
                    }
                }
                return relationList;
            },
            prepareSingleItem: function (regName, fatherId, type, filterZero, filterEmpty) {
                var singleValue = $.trim($(regName).suggest("getValue"));
                var isNum = EpgWeb.Plugin.Validate.checkNum(singleValue)
                if (!isNum) {
                    return null;
                }
                if (filterEmpty) {
                    if ($.trim($(regName).val()) == "") {
                        return null;
                    }
                }
                if (filterZero) {
                    if (singleValue === '0') {
                        return null;
                    }
                }
                return {fatherId: fatherId, "key": parseInt(singleValue), type: type, "value": "" }
            },

            prepareMultipleItem: function (regName, fatherId, type, needValue) {
                var relationList = [];
                needValue = needValue ? true : false;
                var items = $(regName).suggest("getItems");
                $.each(items, function (index, element) {
                    if (element.id != null) {
                        relationList.push({fatherId: fatherId, "key": element.id, type: type, "value": needValue ? element.label : "" });
                    }
                });
                return relationList
            },
            bindEditEvent: function () {
                var self = this;
                $("#qitanId").focusout(function () {
                    var flag = EpgWeb.Plugin.baseCheck({value: $("#qitanId").val(), error: "请输入整数", handler: function (msg) {
                        var helpHint = $("span[for=qitanId]");
                        helpHint.html("请输入整数");
                    }, type: "number"})
                    if (!flag) {
                        return;
                    }
                })

                if (self.dao.cfgName.id > 0) {
                    self.editPic(false);
                    $(".header button").bind("click", function (event) {
                        self.editPic(true);
                    });
                }
                //leftWordsCount
                Program.Util.limitWordCount($("#description"), 200);
                Program.Util.limitWordCount($("#recommendRemark"), 10);

                $("select[name$=SuggestType]").bind("change", function (event) {
                    var $curTarget = $(event.currentTarget)
                    var selectedValue = $curTarget.val();
                    console.log("selectedValue")
                    $curTarget.parent().find("span input").parent().hide();
                    $curTarget.parent().find("span input[name$=_" + selectedValue + "]").parent().show();
                })
                $("select[name=frontSuggestType]").change();
                $("select[name=endSuggestType]").change();
                $("select[name$=SuggestType]").parent().find("span input").show();

                $("input[name=use_puyu_radio]").bind("click", function (event) {
                    var $curTarget = $(event.currentTarget)
                    var puyuDiv = $("#puyuDiv");
                    if ($curTarget.val() == 1) {
                        puyuDiv.show();
                    } else {
                        puyuDiv.hide();
                        puyuDiv.find("input[type=text]").val("");
                    }
                })

                $("select[name=channelCateTag]").bind("change", function (event) {
                    $("#secTagDiv").show();
                    $("#secTagZone").html("数据加载中....");
                    $("#thirdTagDiv").hide();
                    $("#thirdTagZone").html("");
                    var $curTarget = $(event.currentTarget)
                    var selectedValue = $curTarget.val();
                    self.queryForLvOne({channel_id: parseInt(selectedValue), liveDisplay: 1, liveUsed: 1});
                });

                $("input[name=chat_enable]").bind("click", function (event) {
                    var $curTarget = $(event.currentTarget)
                    var chatShowDiv = $("#chatShowDiv");
                    var chatRoomId = $("label[name=chatRoomId]");
                    var daojuFlag = $("input[name=daojuFlag]");
                    if ($curTarget.val() == 1) {
                        chatShowDiv.show();
                        chatRoomId.show();
                        daojuFlag.removeAttr("disabled");
                    } else {
                        chatShowDiv.hide();
                        chatRoomId.hide();
                        $('input[name=daojuFlag][value="0"]').prop("checked", true);
                        $("input[name=daojuFlag]:checked").click();
                        daojuFlag.attr("disabled", "disabled");
                    }
                });

                $("input[name=chat_enable]:checked").click();

                $("input[name=daojuFlag]").bind("click", function (event) {
                    var $curTarget = $(event.currentTarget)
                    var daoju = $("#daoju");
                    var daojuFlag = $("input[name=daojuFlag]");
                    if ($curTarget.val() == 1) {
                        daoju.show();
                        var daojuId = $('#daojuId').data('id');
                        if (daojuId && daojuId !== '') {
                            $("input[name=daoju]").attr("disabled", "disabled");
                            $('#daojuTip').html("渠道号: " + daojuId);
                        }
                        $("label[name=remind_item]").show();
                    } else {
                        daoju.hide();
                        $("label[name=remind_item]").hide();
                    }
                });
                $("input[name=daojuFlag]:checked").click();

                $('#daojuId').bind('input propertychange', function () {
                    if ($(this).val().length == 0) {
                        $('#daojuTip').html("");
                    }
                });

                $("select[name=passport_select]").bind("change", function (event) {
                    var $curTarget = $(event.currentTarget)
                    var selectedValue = $curTarget.val();
                    if (selectedValue == "option_uid") {
                        $("input[name=passport_nickname]").val("");
                        $("input[name=passport_nickname]").parent().find("span").html("");
                        $("#passport_uid_div").css("display", "inline")
                        $("#passport_nickname_div").hide();
                    } else if (selectedValue == "option_nickname") {
                        $("input[name=passport_uid]").val("");
                        $("input[name=passport_uid]").parent().find("span").html("");
                        $("#passport_uid_div").hide();
                        $("#passport_nickname_div").css("display", "inline")
                    }
                })

                $("select[name=project_type_select]").bind("change", function (event) {
                    var $curTarget = $(event.currentTarget)
                    var selectedValue = $curTarget.val();
                    if (selectedValue == "type_sale") {
                        $("input[name=hot][value='0']").prop("checked", true);
                    } else if (selectedValue == "type_nosale") {
                        $("input[name=hot][value='1']").prop("checked", true);
                    }
                })

                var channelEntity = self.dao.getChannel();
                if (channelEntity != null && channelEntity.liveType == 2) {
                    $("#channelCateTag").change();
                    $("select[name=passport_select]").change();
                }


                $("select[name=episodeGrade]").bind("change", function (event) {
                    var $curTarget = $(event.currentTarget);
                    var selectedValue = $curTarget.val();
                    self.updateRecommendRateWithEpisodeGrade(selectedValue);
                });
            },

            updateRecommendRateWithEpisodeGrade: function (val) {
                var recommendVal = 0;
                if (val == '') {
                    recommendVal = 0;
                } else {
                    recommendVal = 3 - parseInt(val) % 10 + 1;
                }
                $("select[name=recommendRate]").val(recommendVal);
            },
            editPic: function (flag) {
                var self = this;
                if (flag) {
                    $(".header button").hide();
                    $(".results button").removeAttr("disabled");
                    $(".operation").removeClass("disabled");
                    $(".uploadButton").removeAttr("disabled");
                    $(".button-manual").removeAttr("disabled");
                    self.dao.cfgName.editPic = true;
                } else {
                    $(".header button").show();
                    $(".header button").removeAttr("disabled");
                    $(".results button").prop("disabled", "disabled");
                    $(".operation").addClass("disabled");
                    $(".uploadButton").prop("disabled", "disabled");
                    $(".button-manual").prop("disabled", "disabled");
                    self.dao.cfgName.editPic = false;
                }
            },
            initDefault: function () {
                $("#qitanId").val("");
                $("input[name=_simple-video]").val("");
                $("input[name=_album]").val("");
                $("input[name=_playlist]").val("");
                $("input[name=use_puyu_radio]").removeAttr("checked");
                $("input[name=bType]").removeAttr("checked");
                $("input[name=bType]").attr("disabled", "disabled");
                $("#puyuShowDiv").hide();
                $("input[name=use_puyu_radio]").removeAttr("checked");
                $("#channelCateTag").val(7);
            },
            initLiveProgramType: function () {
                var self = this;
                var channelEntity = self.dao.getChannel();
                if (channelEntity == null) {
                    return
                }
                var result = self.dao.liveProgramType();
                var selectJDom = $("select[name=liveProgramType]");
                var createDataArr = [];
                $.each(result.data, function (index, obj) {
                    switch (channelEntity.liveType) {
                        case 1:
                            if (obj.key == 6) {
                                createDataArr.push(obj);
                            }
                            break;
                        case 2:
                            if (obj.key < 6) {
                                createDataArr.push(obj);
                            }
                            break;
                        case 3:
                            if (obj.key == 7) {
                                createDataArr.push(obj);
                            }
                            break;
                    }
                });
                $.each(createDataArr, function (index, obj) {
                    $("<option>", {
                        value: obj.key,
                        html: obj.descr
                    }).appendTo(selectJDom);
                });
                selectJDom.bind("change", function (event) {
                    if (event.currentTarget.value == 1) {
                        $("#sportContainer").show()
                    } else {
                        $("#sportContainer").hide()
                    }
                })
            },

            initByProgramData: function () {
                var self = this;
                var programEntity = self.dao.getProgram();
                if (programEntity.category != null) {
                    programEntity.categoryArr = JSON.parse(programEntity.category);
                }

                $("#fatherId").val(programEntity.fatherId);
                self.appendChannelList($("#fatherId").val());
                $("#endPlayTime").val(programEntity.endPlayTime);
                $("#endPlayTime").attr("readonly", "readonly");
                if (programEntity.carouselEpisode > 0) {
                    $("label[name=carouselEpisode]").html(programEntity.carouselEpisode);
                }
                $("#startPlayTime").attr("readonly", "readonly");
                $("#qitanId").val(programEntity.qitanId);
                $("select[name=liveProgramType]").val(programEntity.type);
                if (programEntity.episodeGrade > 0) {
                    $("select[name=episodeGrade]").val(programEntity.episodeGrade);
                }
                if (programEntity.type != 1) {
                    $("#sportContainer").hide();
                }
                $("#pname").val(programEntity.pname);
                $("input[name=weiboTopic]").val(programEntity.weiboTopic);
                $("input[name=leftChannel]").val(programEntity.leftChannel);
                $("input[name=audioChannel]").val(programEntity.audioChannel);
                $("input[name=rightChannel]").val(programEntity.rightChannel);

                $("select[name=recommendRate]").val(programEntity.recommendRate);
                $("select[name=project_type_select]").val(programEntity.projectType || "");
                $("input[name=recommendRemark]").val(programEntity.recommendRemark || "");
                $("input[name=subjectUrl]").val(programEntity.subjectUrl || "");

                $("#description").val(programEntity.description);
                $("#logoUrl").val(programEntity.logoUrl);
                $("#input[name=orderLevel]").val(programEntity.orderBy);
                $("input[name=waterMarkFlag][value='" + programEntity.waterMarkFlag + "']").prop("checked", true);
                $("input[name=subscribe][value='" + programEntity.subscribe + "']").prop("checked", true);
                $("input[name=dan_mu][value='" + programEntity.allowPopups + "']").prop("checked", true);
                $("input[name=qitanMarkFlag][value='" + programEntity.allowComment + "']").prop("checked", true);
                $("input[name=freeStatus][value='" + (programEntity.freeStatus ? 1 : 0) + "']").prop("checked", true)
                $("select[name=vipType]").val(programEntity.vipType);
                $("input[name=qiyiProduct][value='" + (programEntity.qiyiProduct || 0) + "']").prop("checked", true);
                $("input[name=qiyiExclusive][value='" + (programEntity.qiyiExclusive || 0) + "']").prop("checked", true)
                self.fillDataByChannelData();
                self.bindSubmitHandler("edit");
                $("#puyuDiv").hide();
                $("input[name=use_puyu_radio][value='0']").prop("checked", true);
                if (programEntity.barCode != null && programEntity.puyuData != null) {
                    if (self.fillPuYuField(programEntity.puyuData)) {
                        $("input[name=puyu_barCode]").val(programEntity.barCode);
                        $("input[name=suggest_barCode]").val(programEntity.barCode);
                        $("input[name=use_puyu_radio][value='" + 1 + "']").prop("checked", true);
                        $("#puyuDiv").show();
                    }
                }
                if (programEntity.chatRoomId > 0) {
                    $("label[name=chatRoomId]").html("聊天室ID：" + programEntity.chatRoomId);
                }
                $('input[name=chat_enable][value=' + programEntity.chatEnable + ']').prop("checked", true);
                $('input[name=chat_display][value=' + programEntity.chatDisplay + ']').prop("checked", true);
                if (programEntity.chatRoomId > 0 && programEntity.chatEnable == 0) {
                    $("input[name=chat_enable]").attr("disabled", "disabled");
                    $("input[name=chat_display]").attr("disabled", "disabled");
                }

                $('input[name=daojuFlag][value=' + programEntity.daojuEnable + ']').prop("checked", true);
                $('#daojuId').val(programEntity.daojuName);
                $('#daojuId').data("id", programEntity.daojuId);
                if (programEntity.daojuEnable === 1 && typeof programEntity.daojuId !== 'undefined' && programEntity.daojuId !== '') {
                    $('#daojuTip').html("渠道号: " + programEntity.daojuId);
                    $('#daojuId').attr("disabled", "disabled");
                }

                // init puyu relation end;

                var channelEntity = self.dao.getChannel();
                if (channelEntity == null) {
                    return
                }
                if (channelEntity.liveType != 3) {
                    $("#bTypeDiv").hide();
                } else {
                    $("#bTypeDiv").show();
                    $("input[name=bType][value=" + programEntity.live + "]").prop("checked", true);
                }

                if (channelEntity.liveType == 2) {
                    if (programEntity.categoryCheck != null) {
                        $.each(programEntity.categoryCheck, function (i, element) {
                            if (element.level == 1) {
                                $("#channelCateTag").val(element.id);
                                return false;
                            }
                        })
                    }
                    $("#endPlayTime").removeAttr("readonly");
                    $("#startPlayTime").removeAttr("readonly");
                    Program.Util.bindDate("startPlayTime", "endPlayTime", { maxDate: programEntity.endPlayTime, maxDateTime: new Date(programEntity.endPlayTime.replace(/-/g, "/")), minDate: programEntity.startPlayTime, minDateTime: new Date(programEntity.startPlayTime.replace(/-/g, "/"))});
                    $("input[name=startPlayTime]").datetimepicker("setDate", new Date(programEntity.startPlayTime.replace(/-/g, "/")));
                    $("input[name=endPlayTime]").datetimepicker("setDate", new Date(programEntity.endPlayTime.replace(/-/g, "/")));

                    Program.Util.bindDate("streamStartPlayTime", "streamEndPlayTime", { maxDate: programEntity.streamEndPlayTime, maxDateTime: new Date(programEntity.streamEndPlayTime.replace(/-/g, "/")), minDate: programEntity.streamStartPlayTime, minDateTime: new Date(programEntity.streamStartPlayTime.replace(/-/g, "/"))});
                    $("input[name=streamStartPlayTime]").datetimepicker("setDate", new Date(programEntity.streamStartPlayTime.replace(/-/g, "/")));
                    $("input[name=streamEndPlayTime]").datetimepicker("setDate", new Date(programEntity.streamEndPlayTime.replace(/-/g, "/")));

                    $("input[name=freeStatus]").prop("disabled", "disabled");
                    $("#playbackSuggest").val(0);
                } else if (channelEntity.liveType == 1) {
                    $("#pname").prop("disabled", "disabled");
                    $("input[name=freeStatus][value='" + 1 + "']").prop("checked", true);
                    $("input[name=freeStatus][value='" + 1 + "']").parent().parent().hide();
                } else if (channelEntity.liveType == 3) {
                    $("label[name=carouselEpisode]").show();
                    $("input[name=freeStatus]").prop("disabled", "disabled");
                    if (new Date(programEntity.startPlayTime.replace(/-/g, "/")).getTime() - new Date().getTime() > 30 * 60 * 1000) {
                        $("#endPlayTime").removeAttr("readonly");
                        $("#startPlayTime").removeAttr("readonly");
                        Program.Util.bindDate("startPlayTime", "endPlayTime", { maxDate: programEntity.endPlayTime, maxDateTime: new Date(programEntity.endPlayTime.replace(/-/g, "/")), minDate: programEntity.startPlayTime, minDateTime: new Date(programEntity.startPlayTime.replace(/-/g, "/"))});
                        $("input[name=startPlayTime]").datetimepicker("setDate", new Date(programEntity.startPlayTime.replace(/-/g, "/")));
                        $("input[name=endPlayTime]").datetimepicker("setDate", new Date(programEntity.endPlayTime.replace(/-/g, "/")));

                        Program.Util.bindDate("streamStartPlayTime", "streamEndPlayTime", { maxDate: programEntity.streamEndPlayTime, maxDateTime: new Date(programEntity.streamEndPlayTime.replace(/-/g, "/")), minDate: programEntity.streamStartPlayTime, minDateTime: new Date(programEntity.streamStartPlayTime.replace(/-/g, "/"))});
                        $("input[name=streamStartPlayTime]").datetimepicker("setDate", new Date(programEntity.streamStartPlayTime.replace(/-/g, "/")));
                        $("input[name=streamEndPlayTime]").datetimepicker("setDate", new Date(programEntity.streamEndPlayTime.replace(/-/g, "/")));
                    } else {
                        $("#startPlayTimeTip").html('该节目已结束，时间不允许修改');
                    }
                }

                $('input[name=hot][value=' + programEntity.hot + ']').prop("checked", true);
                $('input[name=test][value=' + programEntity.test + ']').prop("checked", true);

                if (channelEntity.liveType != 2) {
                    $("#hotDiv").hide();
                    $("#testDiv").hide();
                }
            },
            bindSubmitHandler: function (type) {
                var self = this;
                self.$validator = Program.Util.getValidator(self.$container, self.config.EDIT_VALIDATOR);
                var submitButton = $("button[type=submit]");
                submitButton.bind("click", function () {
                    if (!self.$validator.form()) {
                        return false;
                    }
                    console.log("ready to submit " + type + "Data");
                    self.submitHandler(type);
                    return false;
                });
            },
            fillDataByChannelData: function () {
                var self = this;
                var element = self.dao.getChannel();
                if (element == null || element.allowPopups != 1) {
                    $("input[name=dan_mu]").attr("disabled", "disabled")
                    $("label[name=danmuHint]").css("display", "inline");
                }
                if (element != null && element.liveType == 2) {
                    $("#channelCateTagDiv").show();
                    $("#secTagDiv").show();
                    $("#thirdTagDiv").show();
                    $("#puyuShowDiv").show();
                    $("#episodeGradeDiv").show();
                    $("span[name=playbackForce]").show();
                    $("label[name=playbackHint]").show();
                    $("#liveTmpDiv").show();
                    $("#projectDiv").show();
                }
            },
            initByChannelData: function () {
                var self = this;
                var element = self.dao.getChannel();
                if (self.dao.cfgName.id == 0) {
                    if (element != null) {
                        $("#fatherId").val(Com.url.getParameter("fatherId"));
                        self.appendChannelList($("#fatherId").val(), true);
                    } else {
                        self.appendChannelList();
                    }
                }
                Program.Util.bindDate("startPlayTime", "endPlayTime");
                Program.Util.bindDate("streamStartPlayTime", "streamEndPlayTime");
                self.bindSubmitHandler("save");
                self.fillDataByChannelData();
            },
            appendChannelList: function (fatherId, newProgram) {
                var self = this;
                var element = self.dao.getChannel()
                if (element != null) {
                    var selectJDom = $("#selectedChannelName");
                    selectJDom.val(element.name);
                    selectJDom.attr("readonly", "readonly");
                    $("input[name=orderLevel]").val(element.orderBy);
                    $('#qitanId').val(element.qitanId);
                    $('#subjectUrlDiv').hide();
                    if (element.liveType == 2) {
                        $('#subjectUrlDiv').show();
                    }
                    $("input[name=subjectUrl]").val(element.subjectUrl || "");

                }
                if (newProgram) {
                    $("input[name=dan_mu][value='" + element.allowPopups + "']").prop("checked", true);
                    $("input[name=qitanMarkFlag][value='" + element.shouldDisplay + "']").prop("checked", true);
                }
            },

            initRelationDataArea: function () {
                var self = this;
                if (self.dao.cfgName.id == 0) {
                    return;
                }
                var programEntity = self.dao.getProgram();
                if (programEntity == null) {
                    self.initByNull();
                    return;
                }
                self.fillRelationData(programEntity.relationList);
            },

            initByNull: function () {
                var self = this;
                EpgWeb.Plugin.showTips({content: "not such data", type: "error"});
                self.dao.cfgName.id = 0;
                $("input[name=dan_mu]").attr("disabled", "disabled")
                $("form[role=form]").submit(function () {
                    EpgWeb.Plugin.showTips({content: "非法数据", type: "error"});
                    return false;
                })
            },

            fillPuYuField: function (puyuData) {
                if (puyuData == null) {
                    return false;
                }
                var self = this;
                try {
                    var puyuJson = null;
                    if (typeof(puyuData ) == "string") {
                        puyuJson = JSON.parse(puyuData);
                    } else {
                        puyuJson = puyuData;
                    }
                    var dataArr = puyuJson.cprContents;
                    var element = dataArr.length > 0 ? dataArr[0] : null;
                    return self.fillPuYuOnClick(element);
                } catch (exception) {
                    console.log(" exception " + exception);
                    return false;
                }
            },

            fillPuYuOnClick: function (puyuData) {
                if (typeof(puyuData) == "string") {
                    console.log("wait to do");
                    return false;
                }
                var element = puyuData;
                if (!element.hasOwnProperty("contractNumber")
                    || !element.hasOwnProperty("videoName")
                    || !element.hasOwnProperty("startTime")
                    || !element.hasOwnProperty("endTime")
                    || !element.hasOwnProperty("cprName")
                    ) {
                    console.log("[fillPuYuOnClick] fail element :" + JSON.stringify(element))
                    return false;
                }
                $("input[name=puyu_contractNumber]").val(element.contractNumber);
                $("input[name=puyu_videoName]").val(element.videoName);
                $("input[name=puyu_startTime]").val(element.startTime);
                $("input[name=puyu_endTime]").val(element.endTime)
                $("input[name=puyu_cprName]").val(element.cprName);
                return true;
            },
            initSuggest: function () {

                var formElement = this;
                var qitanSuggest = {id: "qitanId", options: {
                    source: EpgWeb.urlConfig.redirect,
                    parseValue: function () {
                        return [];
                    },
                    multiple: false,
                    select: function (event, object) {
                        this.value = object.item.id + "";
                        return false;
                    },

                    process: function (json) {
                        var ret = [],
                            self = this,
                            options = self.options,
                            itemData = null;
                        var data = null;
                        if (json == null) {
                            return [];
                        }
                        if (json.code === "A00000") {
                            data = $.isArray(json) ? json : json.data;
                        }
                        if (!data || !data.ids) {
                            return [];
                        }
                        $.map(data.ids, function (item) {
                            itemData = {};
                            itemData[options.valueKey] = item["resourceId"];
                            itemData[options.labelKey] = item["name"];
                            itemData["addDate"] = item["addDate"]
                            ret.push(itemData);
                        });
                        return ret;
                    },
                    method: "post",
                    getParam: function (owner, term) {
                        var requestData = {url: EpgWeb.Constant.thirdUrl_qitan_url, type: "get", params: {name: this.element.val(), resource_type: 1, page_size: 10}};
                        return {"request": JSON.stringify(requestData), timeSign: new Date().getTime()}
                    },

                    template: function (item) {
                        return Program.Util.template.qitanSuggest([item["id"], item["label"], item["addDate"] ])
                    },
                    header: Program.Util.template.qitanSuggest(Program.Config.Header.qitanSuggest)
                }}
                var actorSuggest = {id: "ajaxSuggest", options: {
                    source: EpgWeb.urlConfig.redirect,
                    parseValue: function () {
                        var self = this;
                        var val = this.element.val(),
                            ret = [],
                            items = null,
                            itemData = null,
                            options = self.options;

                        if (val) {
                            items = val.split(';');
                            $.each(
                                items, function (i, item) {
                                    item = item.split(',');
                                    itemData = {};
                                    itemData[options.labelKey] = item[1];
                                    itemData[options.valueKey] = item[0];
                                    ret.push(itemData);
                                }
                            );
                        }
                        this._value('');
                        return ret;
                    },
                    process: function (json) {
                        var ret = [],
                            self = this,
                            options = self.options,
                            itemData = null;
                        var data = null;
                        if (json == null) {
                            return [];
                        }
                        if (json.code === "A00000") {
                            data = $.isArray(json) ? json : json.data;
                        }
                        if (!data) {
                            return [];
                        }
                        $.map(data, function (item) {
                            itemData = {};
                            itemData[options.valueKey] = item["qipuId"];
                            itemData[options.labelKey] = item["properName"];
                            itemData["typeName"] = item["typeName"]
                            itemData["showId"] = item["id"];
                            itemData["gender"] = item.gender == null ? "" : item.gender == 0 ? "男" : "女";
                            itemData["auditStatus"] = item["auditStatus"] == 1 ? "审核通过" : "未审核";
                            itemData["careerName"] = item["careerName"];
                            ret.push(itemData);
                        });
                        return ret;
                    },
                    method: "post",
                    getParam: function (owner, term) {
                        var requestData = {url: EpgWeb.Constant.thirdUrl_audit_people, type: "get", params: {word: this.element.val()}};
                        return {"request": JSON.stringify(requestData), timeSign: new Date().getTime()}
                    },

                    template: function (item) {
                        var formatArr = [];
                        formatArr.push(item.showId);
                        formatArr.push(item["label"]);
                        formatArr.push(item["careerName"]);
                        formatArr.push(item.gender);
                        formatArr.push(item.typeName);
                        formatArr.push(item.auditStatus);
                        return Program.Util.template.actorSuggest(formatArr)
                    },
                    header: Program.Util.template.actorSuggest(Program.Config.Header.actorSuggest)
                }};

                var playbackSuggest = {
                    id: "playbackSuggest",
                    options: {
                        source: EpgWeb.urlConfig.redirect,
                        method: "post",
                        multiple: false,
                        parseValue: function () {
                            return [];
                        },
                        select: function (event, object) {
                            this.value = object.item.id + "";
                            return false;
                        },
                        getParam: function (term) {
                            var requestData = {url: EpgWeb.Constant.thirdUrl_video_url, type: "get", params: {word: term, type: "properTitle"}, needCookie: true};
                            return {"request": JSON.stringify(requestData), timeSign: new Date().getTime()}
                        },

                        process: function (json) {
                            var ret = [],
                                self = this,
                                options = self.options,
                                itemData = null;
                            var data = null;
                            if (json == null) {
                                return [];
                            }
                            if (json.code === "A00000") {
                                data = $.isArray(json) ? json : json.data;
                            }
                            if (!data) {
                                return [];
                            }
                            $.map(data, function (item) {
                                if (item["qipuId"] == null || item["qipuId"] == 0) {
                                    return true;
                                }
                                itemData = {};
                                itemData[options.valueKey] = item["qipuId"];
                                itemData[options.labelKey] = item["properTitle"];
                                itemData[self._displayKey] = item["qipuId"];
                                itemData["channelName"] = item["channelName"];
                                itemData["globalPublishDate"] = item["globalPublishDate"];
                                itemData["isPurchase"] = item["isPurchase"];
                                itemData["pagePublishStatus"] = item["pagePublishStatus"];
                                ret.push(itemData);
                            });
                            return ret;
                        },

                        template: function (item) {
                            var formatArr = [];
                            formatArr.push(item["id"]);
                            formatArr.push(item["label"]);
                            formatArr.push(item["channelName"]);
                            formatArr.push(item.globalPublishDate);
                            formatArr.push(Program.Util.formatter.purchase(item.isPurchase));
                            formatArr.push(Program.Util.formatter.publishStatus(item.pagePublishStatus));
                            return Program.Util.template.playbackSuggest(formatArr);
                        },
                        header: Program.Util.template.playbackSuggest(Program.Config.Header.playbackSuggest)
                    }
                };

                var defaultHeaderHtml = Program.Util.template.albumSuggest(Program.Config.Header.albumSuggest);

                var videoSuggest = {
                    options: {
                        source: EpgWeb.urlConfig.redirect,
                        method: "post",
                        parseValue: function () {
                            var self = this;
                            var val = this.element.val(),
                                ret = [],
                                items = null,
                                itemData = null,
                                options = self.options;

                            if (val) {
                                items = val.split(';');
                                $.each(
                                    items, function (i, item) {
                                        item = item.split(',');
                                        itemData = {};
                                        itemData[self._showKey] = item[0];
                                        itemData[options.labelKey] = item[1];
                                        itemData[options.valueKey] = item[0];
                                        ret.push(itemData);
                                    }
                                );
                            }
                            this._value('');
                            return ret;
                        },

                        getParam: function (term) {
                            var requestData = {url: EpgWeb.Constant.thirdUrl_video_url, type: "get", params: {word: term, type: "properTitle"}, needCookie: true};
                            return {"request": JSON.stringify(requestData), timeSign: new Date().getTime()}
                        },
                        process: function (json) {
                            var ret = [],
                                self = this,
                                options = self.options,
                                itemData = null;
                            var data = null;
                            if (json == null) {
                                return [];
                            }
                            if (json.code === "A00000") {
                                data = $.isArray(json) ? json : json.data;
                            }
                            if (!data) {
                                return [];
                            }
                            $.map(data, function (item) {
                                if (item["qipuId"] == null || item["qipuId"] == 0) {
                                    return true;
                                }
                                itemData = {};
                                itemData[options.valueKey] = item["qipuId"];
                                itemData[options.labelKey] = item["properTitle"];
                                itemData[self._showKey] = item["qipuId"];
                                itemData["channelName"] = item["channelName"];
                                itemData["copyrightEndTime"] = item["copyrightEndTime"] ? item["copyrightEndTime"] : null;
                                itemData["isPurchase"] = item["isPurchase"];
                                itemData["pagePublishStatus"] = item["pagePublishStatus"];
                                ret.push(itemData);
                            });
                            return ret;
                        },
                        template: function (item) {
                            return Program.Util.template.templateSuggest(item)
                        },
                        header: defaultHeaderHtml
                    }
                }

                var albumSuggest = {
                    options: {
                        source: EpgWeb.urlConfig.redirect,
                        method: "post",
                        multiple: false,
                        parseValue: function () {
                            return [];
                        },
                        select: function (event, object) {
                            this.value = object.item.id + "";
                            return false;
                        },
                        getParam: function (term) {
                            var requestData = {url: EpgWeb.Constant.thirdUrl_album_url, type: "get", params: {word: term, type: "properTitle"}, needCookie: true};
                            return {"request": JSON.stringify(requestData), timeSign: new Date().getTime()}
                        },
                        process: function (json) {
                            var ret = [],
                                self = this,
                                options = self.options,
                                itemData = null;
                            var data = null;
                            if (json == null) {
                                return [];
                            }
                            if (json.code === "A00000") {
                                data = $.isArray(json) ? json : json.data;
                            }
                            if (!data) {
                                return [];
                            }
                            $.map(data, function (item) {
                                if (item["qipuId"] == null || item["qipuId"] == 0) {
                                    return true;
                                }
                                itemData = {};
                                itemData[options.valueKey] = item["qipuId"];
                                itemData[options.labelKey] = item["properTitle"];
                                itemData["channelName"] = item["channelName"];
                                itemData["copyrightEndTime"] = item["copyright"] ? item["copyright"][0].copyrightEndTime : null;
                                itemData["isPurchase"] = item["isPurchase"];
                                itemData["pagePublishStatus"] = item["pagePublishStatus"];
                                ret.push(itemData);
                            });
                            return ret;
                        },
                        template: function (item) {
                            return Program.Util.template.templateSuggest(item)
                        },
                        header: defaultHeaderHtml
                    }
                }

                var playListSuggest = {
                    options: {
                        source: EpgWeb.urlConfig.redirect,
                        method: "post",
                        multiple: false,
                        parseValue: function () {
                            return [];
                        },

                        select: function (event, object) {
                            this.value = object.item.id + "";
                            return false;
                        },

                        getParam: function (term) {
                            var requestData = {url: EpgWeb.Constant.thirdUrl_playlist_url, type: "get", params: {word: term, type: "properTitle"}, needCookie: true};
                            return {"request": JSON.stringify(requestData), timeSign: new Date().getTime()}
                        },
                        process: function (json) {
                            var ret = [],
                                self = this,
                                options = self.options,
                                itemData = null;
                            var data = null;
                            if (json == null) {
                                return [];
                            }
                            if (json.code === "A00000") {
                                data = $.isArray(json) ? json : json.data;
                            }
                            if (!data) {
                                return [];
                            }
                            $.map(data, function (item) {
                                if (item["qipuId"] == null || item["qipuId"] == 0) {
                                    return true;
                                }
                                itemData = {};
                                itemData[options.valueKey] = item["qipuId"];
                                itemData[options.labelKey] = item["name"];
                                itemData["channelName"] = item["channelName"];
                                itemData["copyrightEndTime"] = "";
                                itemData["isPurchase"] = "";
                                itemData["pagePublishStatus"] = item["pagePublishStatus"];
                                ret.push(itemData);
                            });
                            return ret;
                        },
                        template: function (item) {
                            return Program.Util.template.templateSuggest(item)
                        },
                        header: defaultHeaderHtml
                    }
                }

                var puyuSuggest = {
                    id: "suggest_barCode",
                    options: {
                        source: EpgWeb.urlConfig.queryPuYu,
                        parseValue: function () {
                            return [];
                        },
                        ignoreWord: true,
                        multiple: false,
                        select: function (event, object) {
                            var flag = formElement.fillPuYuOnClick(object.item);
                            if (flag == true) {
                                $("input[name=puyu_barCode]").val(object.item.value);
                                $("input[name=suggest_barCode]").val(object.item.value);
                            }
                            return false;
                        },

                        process: function (json) {
                            var ret = [],
                                self = this,
                                options = self.options,
                                itemData = null;
                            var data = null;
                            if (json == null || json.code != "A00000") {
                                return [];
                            }
                            data = JSON.parse(json.data);
                            $.map(data.cprContents, function (item) {
                                itemData = {};
                                itemData[options.valueKey] = item["contractId"];
                                itemData[options.labelKey] = $("input[name=suggest_barCode]").val();
                                itemData["contractNumber"] = item["contractNumber"];
                                itemData["videoName"] = item["videoName"];
                                itemData["cprName"] = item["cprName"];
                                itemData["startTime"] = item["startTime"];
                                itemData["endTime"] = item["endTime"];
                                itemData["produceName"] = item["produceName"] || "";
                                itemData["produceTime"] = item["produceTime"] || "";
                                itemData["actors"] = item["actors"] || "";
                                itemData["directors"] = item["directors"] || "";
                                ret.push(itemData);
                            });
                            return ret;
                        },
                        method: "post",
                        getParam: function (term) {
                            return { "barCode": term };
                        },

                        template: function (item) {
                            var formatArr = [];
                            formatArr.push(item["label"]);
                            formatArr.push(item["videoName"]);
                            formatArr.push(item["produceName"]);
                            formatArr.push(item["produceTime"]);
                            formatArr.push(item["actors"]);
                            formatArr.push(item["directors"]);
                            formatArr.push(item["cprName"]);
                            formatArr.push(item["contractNumber"]);
                            formatArr.push(item["startTime"] + "~" + item["endTime"]);
                            return Program.Util.template.puyuSuggest(formatArr)
                        },
                        header: Program.Util.template.puyuSuggest(Program.Config.Header.puyuSuggest)
                    }
                }

                var votePKSuggest = {
                    id: "votePK",
                    options: {
                        source: EpgWeb.urlConfig.redirect,
                        method: "post",
                        multiple: false,
                        parseValue: function () {
                            return [];
                        },
                        select: function (event, object) {
                            this.value = object.item.id + "";
                            return false;
                        },
                        getParam: function (term) {
                            var requestData = {url: Program.Constant.vote_inner_url, type: "get", params: {title: term, source: 6}};
                            return {"request": JSON.stringify(requestData), timeSign: new Date().getTime()}
                        },
                        process: function (json) {
                            var ret = [],
                                self = this,
                                options = self.options,
                                itemData = null;
                            var data = null;
                            if (json == null) {
                                return [];
                            }
                            if (json.code === "A00000") {
                                data = $.isArray(json) ? json : json.data;
                            }
                            if (!data) {
                                return [];
                            }
                            $.map(data, function (item) {
                                itemData = {};
                                itemData[options.valueKey] = item["voteid"];
                                itemData[options.labelKey] = item["mainTitle"];
                                itemData["createTime"] = item["createTime"] || 0;
                                if (itemData["createTime"] > 0) {
                                    itemData["createTime"] = Program.Util.formatDateTimeFormat(new Date(itemData["createTime"]));
                                } else {
                                    itemData["createTime"] = "";
                                }
                                itemData["title"] = item["mainTitle"];
                                ret.push(itemData);
                            });
                            return ret;
                        },
                        template: function (item) {
                            return Program.Util.template.voteSuggest([ item["id"], item["title"], item["createTime"]]);
                        },
                        //    header: defaultVoteHeaderHtml
                        header: Program.Util.template.voteSuggest(Program.Config.Header.voteSuggest)
                    }
                }
                var voteRankSuggest = {
                    id: "voteRank",
                    options: {
                        source: EpgWeb.urlConfig.redirect,
                        method: "post",
                        multiple: false,
                        select: function (event, object) {
                            this.value = object.item.id + "";
                            return false;
                        },
                        parseValue: function () {
                            return [];
                        },
                        getParam: function (term) {
                            var requestData = {url: Program.Constant.vote_inner_url, type: "get", params: {title: term, source: 7}};
                            return {"request": JSON.stringify(requestData), timeSign: new Date().getTime()}
                        },
                        process: function (json) {
                            var ret = [],
                                self = this,
                                options = self.options,
                                itemData = null;
                            var data = null;
                            if (json == null) {
                                return [];
                            }
                            if (json.code === "A00000") {
                                data = $.isArray(json) ? json : json.data;
                            }
                            if (!data) {
                                return [];
                            }
                            $.map(data, function (item) {
                                itemData = {};
                                itemData[options.valueKey] = item["voteid"];
                                itemData[options.labelKey] = item["mainTitle"];
                                itemData["createTime"] = item["createTime"] || 0;
                                if (itemData["createTime"] > 0) {
                                    itemData["createTime"] = Program.Util.formatDateTimeFormat(new Date(itemData["createTime"]));
                                } else {
                                    itemData["createTime"] = "";
                                }
                                itemData["title"] = item["mainTitle"];
                                ret.push(itemData);
                            });
                            return ret;
                        },
                        template: function (item) {
                            return Program.Util.template.voteSuggest([ item["id"], item["title"], item["createTime"]]);
                        },
                        header: Program.Util.template.voteSuggest(Program.Config.Header.voteSuggest)
                    }
                }


                var daojuSuggest = {
                    id: "daojuId",
                    options: {
                        source: EpgWeb.urlConfig.redirect,
                        method: "post",
                        multiple: false,
                        select: function (event, object) {
                            this.value = object.item.label + "";
                            $('#daojuTip').html("渠道号: " + object.item.id);
                            return false;
                        },
                        parseValue: function () {
                            return [];
                        },
                        getParam: function (term) {
                            var params = {
                                api_key: 'epg',
                                format: 'json',
                                ip: Program.Constant.daoju_ip,
                                partner_name: term,
                                time: Math.round(new Date().getTime() / 1000),
                                //time: 1459163882,
                                version: '1.0.0'
                            };
                            var paramSign = Program.Util.createSign(params, Program.Constant.daoju_secret);
                            params.sign = paramSign;

                            var requestData = {url: Program.Constant.daoju_inner_url, type: "post",
                                params: params
                            };
                            return {"request": JSON.stringify(requestData), timeSign: new Date().getTime()}
                        },
                        process: function (json) {
                            var ret = [],
                                self = this,
                                options = self.options,
                                itemData = null;
                            var data = null;
                            if (json == null) {
                                return [];
                            }
                            if (json.code === "A00000") {
                                data = $.isArray(json) ? json : json.data;
                            }
                            if (!data) {
                                return [];
                            }

                            $.map(data, function (item) {
                                itemData = {};
                                itemData[options.valueKey] = item["partner_code"];
                                itemData[options.labelKey] = item["partner_name"];
                                itemData["add_time"] = item["add_time"];
                                itemData["admin_username"] = item["admin_username"];
                                ret.push(itemData);
                            });
                            return ret.slice(0, 10);
                        },
                        template: function (item) {
                            return Program.Util.template.daojuSuggest([item["id"], item["label"], item["add_time"], item["admin_username"]]);
                        },
                        header: Program.Util.template.daojuSuggest(Program.Config.Header.daojuSuggest)
                    }
                };

                $("#" + qitanSuggest.id).suggest(qitanSuggest.options);
                $("#" + actorSuggest.id).suggest(actorSuggest.options);
                $("#" + playbackSuggest.id).suggest(playbackSuggest.options);
                $("input[name$=_simple-video]").suggest(videoSuggest.options);
                $("input[name$=_album]").suggest(albumSuggest.options);
                $("input[name$=_playlist]").suggest(playListSuggest.options);
                $("#" + puyuSuggest.id).suggest(puyuSuggest.options);
                $("#" + votePKSuggest.id).suggest(votePKSuggest.options);
                $("#" + voteRankSuggest.id).suggest(voteRankSuggest.options);
                $("#" + daojuSuggest.id).suggest(daojuSuggest.options);
            },

            submitHandler: function submitHandler(type) {
                if ($.trim($("#votePK").val()) != "" && $("#votePK").val() != $("#votePK").suggest("getValue")) {
                    EpgWeb.Plugin.showTips({content: "PK投票 不允许手动修改！", type: "error"});
                    return;
                }
                if ($.trim($("#voteRank").val()) != "" && $("#voteRank").val() != $("#voteRank").suggest("getValue")) {
                    EpgWeb.Plugin.showTips({content: "列表投票 不允许手动修改！", type: "error"});
                    return;
                }

                var self = this;
                var modelData = self.prepareModel();
                var channelEntity = self.dao.getChannel();
                if (channelEntity != null) {
                    if (channelEntity.liveType == 2) {
                        if (!self.checkLiveType(modelData)) {
                            return;
                        }
                    }
                }
                if (!self.checkModel(modelData)) {
                    return;
                }
                $("button[name=submitBtn]").prop("disabled", "disabled");
                self.remoteCheck.doCheck(null, function (data) {
                        var allSuccess = true;
                        var errorMsg = [];
                        if (data != null) {
                            $.each(data, function (index, element) {
                                if (!element.success) {
                                    allSuccess = false;
                                    errorMsg.push(element.msg);
                                }
                            });
                        }
                        if (!allSuccess) {
                            EpgWeb.Plugin.showTips({
                                content: errorMsg.join("\n"),
                                type: "error"
                            })
                            $("button[name=submitBtn]").removeAttr("disabled");
                            return;
                        }

                        var sendImageDatas = null;
                        if (self.dao.cfgName.id == 0 || self.dao.cfgName.editPic) {
                            sendImageDatas = self.getSendImageData();
                        }
                        var task = self.task.sendTask(modelData, sendImageDatas);
                        task.regName = type == "edit" ? "editData" : "saveData";
                        task.options.url = type == "edit" ? EpgWeb.urlConfig.programEdit : EpgWeb.urlConfig.programAdd;
                        EpgWeb.ajaxQueue.push(task.regName, task.options, null, true);
                        EpgWeb.ajaxQueue.startLoad();
                    },
                    function startRemoveCheck(saveData) {
                        if (saveData != null) {
                            $.each(saveData, function (index, element) {
                                var requestData = {url: EpgWeb.urlConfig.getQiPuBaseUrl(element.value), type: "get"};
                                $.ajax({
                                    url: EpgWeb.urlConfig.redirect,
                                    type: "post",
                                    dataType: "json",
                                    data: {"request": JSON.stringify(requestData), timeSign: new Date().getTime()},
                                    success: function (data) {
                                        console.log("data" + JSON.stringify(data))
                                        element.complete = true;
                                        if (data != null && data.hasOwnProperty("id")) {
                                            element.success = true;
                                            if (data["episode_summary"] != null && data["episode_summary"].length > 200) {
                                                element.success = false;
                                                element.msg = "奇谱ID：" + element.value + " 关联节目超过200个!";
                                            }
                                        } else {
                                            element.success = false;
                                            element.msg = "验证失败:" + element.value;
                                        }
                                        console.log("element.msg" + element.msg);
                                    },
                                    error: function (data) {
                                        element.complete = true;
                                        element.success = false;
                                        element.msg = "检测请求失败:" + element.value;
                                        console.log("data" + JSON.stringify(data) + ";" + element.msg)
                                    }
                                })
                            })
                        }
                    }
                )
            },
            checkLiveType: function (modelData) {
                var checkArr = [];
                checkArr.push({value: $('#playbackSuggest').val().length, error: "关联直转点后节目Id不能为空", type: "gt", other: 0 })
                checkArr.push({value: $('#episodeGrade').val().length, error: "节目等级不能为空", type: "gt", other: 0 });
                checkArr.push({value: $("input:radio[name=use_puyu_radio]:checked").val(), error: "必须选择关联璞玉信息", type: "not_empty" });
                if ($("input:radio[name=use_puyu_radio]:checked").val() == 1) {
                    checkArr.push({value: $("input[name=suggest_barCode]").val().length, error: "尚未设置关联璞玉信息", type: "gt", other: 0 });
                    checkArr.push({value: $("input[name=suggest_barCode]").val(), error: "璞玉条形码与数据不一致", type: "eq", other: $("input[name=puyu_barCode]").val() });
                    modelData.barCode = $("input[name=puyu_barCode]").val();
                }
                if (!EpgWeb.Plugin.Validate.batchCheck(checkArr)) {
                    console.log("interrupt checkLiveType checkRepeat")
                    return false;
                }
                var checkLevel1 = false;
                var checkLevel2 = false;
                var checkLevel3 = false;
                var hasThirdCategory = $("input[name=third_category]");
                if (hasThirdCategory.length == 0) {
                    checkLevel3 = true;
                }
                if (modelData.categoryCheck != null) {
                    $.each(modelData.categoryCheck, function (i, element) {
                        if (element.level == 1) {
                            checkLevel1 = true;
                        }
                        if (element.level == 2) {
                            checkLevel2 = true;
                        }
                        if (element.level == 3) {
                            checkLevel3 = true;
                        }
                    })
                    delete modelData.categoryCheck;
                }
                //if (!checkLevel2) {
                //    EpgWeb.Plugin.showTips({content: "必须选择一个二级分类", type: "error"});
                //    return false;
                //}
                //if (!checkLevel3) {
                //    EpgWeb.Plugin.showTips({content: "必须选择一个三级分类", type: "error"});
                //    return false;
                //}
                return true;
            },

            checkModel: function (modelData) {
                var self = this;
                self.remoteCheck.clear();
                var checkArr = [];
                var frontValue = $("select[name=frontSuggestType]").val();
                var endValue = $("select[name=endSuggestType]").val();
                var items = null;
                if (frontValue == "simple-video") {
                    items = $('#appendFront_' + frontValue).suggest("getItems");
                    checkArr.push({value: items.length, error: "数量不能大于200", type: "le", other: 200})
                } else {
                    if ($('#appendFront_' + frontValue).val().length > 0) {
                        checkArr.push({value: $('#appendFront_' + frontValue).val(), error: "节目集锦需要数字格式", type: "number"});
                        if ("album" == frontValue) {
                            checkArr.push({value: $('#appendFront_' + frontValue).val(), error: "专辑qipuId格式错误", type: "endsWith", other: "01"});
                        } else if ("playlist" == frontValue) {
                            checkArr.push({value: $('#appendFront_' + frontValue).val(), error: "播单qipuId格式错误", type: "endsWith", other: "02"});
                        }
                        self.remoteCheck.addToCheck({regName: '#appendFront_' + frontValue, value: $('#appendFront_' + frontValue).val(), modeType: frontValue })
                    }

                }
                if (endValue == "simple-video") {
                    items = $('#appendEnd_' + endValue).suggest("getItems");
                    checkArr.push({value: items.length, error: "数量不能大于200", type: "le", other: 200})
                } else {
                    if ($('#appendEnd_' + frontValue).val().length > 0) {
                        checkArr.push({value: $('#appendEnd_' + frontValue).val(), error: "节目集锦需要数字格式", type: "number"})
                        if ("album" == frontValue) {
                            checkArr.push({value: $('#appendEnd_' + frontValue).val(), error: "专辑qipuId格式错误", type: "endsWith", other: "01"});
                        } else if ("playlist" == frontValue) {
                            checkArr.push({value: $('#appendEnd_' + frontValue).val(), error: "播单qipuId格式错误", type: "endsWith", other: "02"});
                        }
                        self.remoteCheck.addToCheck({regName: '#appendEnd_' + frontValue, value: $('#appendEnd_' + frontValue).val(), modeType: frontValue })
                    }
                }
                if ($('#playbackSuggest').val().length > 0) {
                    if ($('#playbackSuggest').val() !== '0') {
                        checkArr.push({value: $('#playbackSuggest').val(), error: "关联直转点需要数字格式", type: "number"})
                        checkArr.push({value: $('#playbackSuggest').val(), error: "节目qipuId格式错误", type: "endsWith", other: "00"});
                    }
                }
                if (!EpgWeb.Plugin.Validate.batchCheck(checkArr)) {
                    console.log("interrupt checkRepeat")
                    return false;
                }

                checkArr = [];
                checkArr.push({value: [modelData.streamStartPlayTime, modelData.streamEndPlayTime, modelData.startPlayTime, modelData.endPlayTime, modelData.pname], error: "请填写完整", type: "not_empty"});
                checkArr.push({value: [modelData.startPlayTime, modelData.endPlayTime, modelData.streamStartPlayTime, modelData.streamEndPlayTime], error: ["节目开始时间日期格式错误", "节目结束时间日期格式错误", "流开始时间日期格式错误", "流结束时间日期格式错误"], type: "date"});
                //   checkArr.push({value: modelData.pname.length, error: "节目名称长度不能超过40", type: "le", other: 40 })
                checkArr.push({value: modelData.endPlayTime, error: "节目结束时间需要大于节目开始时间", type: "gt", other: modelData.startPlayTime});
                checkArr.push({value: modelData.streamEndPlayTime, error: "流结束时间需要大于流开始时间", type: "gt", other: modelData.streamStartPlayTime});
                checkArr.push({value: modelData.streamEndPlayTime, error: "流结束时间不能小于节目结束时间", type: "ge", other: modelData.endPlayTime});
                checkArr.push({value: modelData.streamStartPlayTime, error: "流开始时间不能大于节目开始时间", type: "le", other: modelData.startPlayTime});
                checkArr.push({value: modelData.subjectUrl, error: "专题页url格式错误,请修改后保存!", type: "self_design", checkCall: function (checkData, checkValue) {
                    if (checkValue == null || checkValue.length == 0) {
                        return true;
                    }
                    return checkValue.split('://')[0] === 'http';
                }});
                if (!EpgWeb.Plugin.Validate.batchCheck(checkArr)) {
                    console.log("interrupt checkRepeat")
                    return false;
                }
                var channelEntity = self.dao.getChannel();
                var checkProgram = (new Date(modelData.endPlayTime.replace(/-/g, "/")).getTime() - new Date(modelData.startPlayTime.replace(/-/g, "/")).getTime()) / 1000;
                if (channelEntity.maxPlaybackPeriod < checkProgram) {
                    console.log("checkProgram:" + checkProgram + ";maxPlaybackPeriod:" + channelEntity.maxPlaybackPeriod);
                    SystemDialog.queryAlert("回看时间必须大于或等于节目时间<br>无法完成提交，请先修改回看时间！");
                    return false;
                }
                return true;
            },

            getSendImageData: function () {
                var self = this;
                var sumbitImgData = {};
                sumbitImgData.imageDatas = [];
                var imageData = {"materials": [], "images": [], "contentRank": "0", "useType": "699"}
                sumbitImgData.imageDatas.push(imageData);
                var cropValues = $("#AlbumEditScreenCorp").data('imageCrop').getValue();
                console.log(JSON.stringify(cropValues));
                $(".item img").each(function (i, imgTarget) {
                    imageData.materials.push(self.getFormatMaterial($(imgTarget)))
                });
                for (var key in cropValues) {
                    imageData.images.push(self.getFormatCrop(cropValues[key]))
                }
                if (imageData.materials.length == 0 && imageData.images.length == null) {
                    return null;
                }
                return sumbitImgData.imageDatas;
            },


            getFormatMaterial: function ($target) {
                return {
                    "area": "bj",
                    //   "area": "sh",
                    "fromType": "0",
                    "location": $target.data("spath"),
                    "width": $target.data("width"),
                    "height": $target.data("height")
                }
            },
            getFormatCrop: function (cropTarget) {
                return {
                    "materialLocation": cropTarget.spath,
                    "editInfo": {
                        "cutPosition": [cropTarget.x1, cropTarget.y1, cropTarget.y2 - cropTarget.y1, cropTarget.x2 - cropTarget.x1].join(","),
                        "scale": cropTarget.w + ":" + cropTarget.h
                    }
                }
            },

            makeUpCategory: function () {
                var category = [];
                var rootId = Number($("#channelCateTag").val());
                category.push({id: rootId, level: 1 });
                var secArr = $("input[name=sec_category]:checked");
                var jElement = null;
                $.each(secArr, function (i, element) {
                    jElement = $(element);
                    category.push({id: parseInt(jElement.val()), pid: rootId, name: jElement.attr("data-name"), level: 2});
                });

                var thirdArr = $("input[name=third_category]:checked");
                $.each(thirdArr, function (i, element) {
                    jElement = $(element);
                    category.push({ pid: parseInt(jElement.attr("data-pid")), id: jElement.val(), name: jElement.attr("data-name"), level: 3});
                });
                return category
            },

            initDialog: function () {
                var self = this;
                $("#oepn-item-dlg").dialog({
                    title: "提示",
                    autoOpen: false,
                    width: 400,
                    modal: true,
                    dialogClass: 'alert',
                    resizable: false
                })
                $(".ui-dialog-titlebar-close").html('<span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span><span class="ui-button-text">close</span>');
                $("button[name=con_created]").bind("click", function (event) {
                    $("#oepn-item-dlg").dialog("close");
                    self.submitHandler("save", true);
                })
                $("button[name=con_cancel]").bind("click", function (event) {
                    $("#oepn-item-dlg").dialog("close");
                })
            },
            initEditPicZone: function () {
                var self = this;
                var picEnity = null;
                if (self.dao.cfgName.id == 0) {
                    if (self.dao.channelId > 0) {
                        picEnity = self.dao.getChannel();
                        if (picEnity != null && picEnity.liveType != 2) {
                            picEnity = null;
                        }
                    }
                } else {
                    picEnity = self.dao.getProgram();
                }
                if (picEnity == null || picEnity.logoUrl == null || picEnity.logoUrl == "") {
                    return;
                }
                Program.Util.imageObjectEcho(self.$container, picEnity.logoUrl);
            },
            bindValidate: function () {
                var self = this;
                var channelEntity = self.dao.getChannel();
                if (channelEntity != null && channelEntity.liveType == 2) {
                    $("input[name=passport_uid]").bind("focusout", function (event) {
                        var curTarget = $(event.currentTarget);
                        var $sec_curTarget = curTarget.val();
                        var helpblock = curTarget.parent().find("span");
                        self.doPassPortClean(helpblock, curTarget);
                        if (!/^[0-9]*$/.test($sec_curTarget)) {
                            self.doPassPortError(helpblock, curTarget, "请输入数字");
                            return
                        }
                        if ($.trim($sec_curTarget).length == 0) {
                            return;
                        } else {
                            var requestData = {url: EpgWeb.Constant.thirdUrl_passport_url, type: "get", params: {uid: $sec_curTarget }, needCookie: true};
                            $.ajax({
                                url: EpgWeb.urlConfig.redirect,
                                type: "post",
                                dataType: "json",
                                data: {"request": JSON.stringify(requestData), timeSign: new Date().getTime()},
                                success: function (data) {
                                    if (data != null) {
                                        if ("A00000" == data.code) {
                                            self.doPassPortSuc(helpblock, data.data);
                                        } else {
                                            if (data.msg.indexOf("指定的uid不存在") != -1) {
                                                data.msg = "uid不存在,请重新输入";
                                            }
                                            self.doPassPortError(helpblock, curTarget, data.msg);
                                        }
                                    } else {
                                        self.doPassPortError(helpblock, curTarget)
                                    }
                                },
                                error: function (data) {
                                    self.doPassPortError(helpblock, curTarget)
                                }
                            })
                        }
                    });
                    $("input[name=passport_nickname]").bind("focusout", function (event) {
                        var curTarget = $(event.currentTarget);
                        var $sec_curTarget = curTarget.val();
                        var helpblock = curTarget.parent().find("span");
                        self.doPassPortClean(helpblock, curTarget);
                        if ($.trim($sec_curTarget).length == 0) {
                            return;
                        } else {
                            var requestData = {url: EpgWeb.Constant.thirdUrl_passport_url, type: "post", params: {nickname: $sec_curTarget }, needCookie: true};
                            $.ajax({
                                url: EpgWeb.urlConfig.redirect,
                                type: "post",
                                dataType: "json",
                                data: {"request": JSON.stringify(requestData), timeSign: new Date().getTime()},
                                success: function (data) {
                                    if (data != null) {
                                        if ("A00000" == data.code) {
                                            self.doPassPortSuc(helpblock, data.data);
                                            $("input[name=passport_nickname]").val(data.data.userinfo.nickname);
                                        } else {
                                            if (data.msg.indexOf("用户不存在") != -1) {
                                                data.msg = "昵称不存在,请重新输入";
                                            }
                                            self.doPassPortError(helpblock, curTarget, data.msg);
                                        }
                                    } else {
                                        self.doPassPortError(helpblock, curTarget)
                                    }
                                },
                                error: function (data) {
                                    self.doPassPortError(helpblock, curTarget)
                                }
                            })
                        }
                    })
                }
            },
            doPassPortClean: function (helpblock, curTarget) {
                helpblock.html("");
                $("input[name=uid_hidden]").val("");
                $("input[name=nickname_hidden]").val("");
                $("#passport_div").removeClass("error");
                curTarget.removeClass("help-block");
            },

            doPassPortSuc: function (helpblock, data) {
                helpblock.html("");
                $("input[name=uid_hidden]").val(data.userinfo.uid);
                $("input[name=nickname_hidden]").val(data.userinfo.nickname);
            },

            doPassPortError: function (helpblock, curTarget, msg) {
                if (msg == null) {
                    msg = "请求发生异常!"
                }
                helpblock.show();
                helpblock.html(msg);
                $("#passport_div").addClass("error");
                curTarget.addClass("help-block");
            },

            fillRelationData: function (relationEntityList) {
                var self = this;
                var nameArr = "base1Arr,base3Arr,base4Arr,base5Arr,base6Arr,base7Arr,base106Arr,base107Arr".split(",");
                var relationObj = {};
                $.each(nameArr, function (index, paramName) {
                    relationObj[paramName] = [];
                })

                var passportData = {uid: "", nickname: ""};
                var itemModel = null;
                if (relationEntityList != null && relationEntityList.length > 0) {
                    $.each(relationEntityList, function (index, element) {
                        itemModel = {};
                        itemModel.id = element.key;
                        itemModel.label = element.value;
                        switch (element.type) {
                            case 1:
                            case 3:
                            case 4:
                            case 5:
                            case 6:
                            case 7:
                            case 106:
                            case 107:
                                relationObj["base" + element.type + "Arr"].push(itemModel);
                                break;
                            case 201:
                                $("select[name=live_temp_other]").val(element.value)
                                break;
                            case 301:
                                passportData.uid = element.value;
                                if (element.key == 1) {
                                    passportData.key = "uid";
                                }
                                break;
                            case 302:
                                passportData.nickname = element.value;
                                if (element.key == 1) {
                                    passportData.key = "nickname";
                                }
                                break;
                        }
                    })
                }
                self.addMultipleItem(relationObj["base1Arr"], '#ajaxSuggest', false);
                self.addSingleItem(relationObj["base7Arr"], '#playbackSuggest');
                self.addSingleItem(relationObj["base106Arr"], '#votePK');
                self.addSingleItem(relationObj["base107Arr"], '#voteRank');
                $.each(relationObj["base3Arr"], function (index, target) {
                    var $addBtn = $("#addndelSample3").find("button[class='btn add blue-btn']");
                    $addBtn.parent().find("input[name=base_3_team]").val(target.label);
                    $addBtn.parent().find("input[name=base_3_score]").val(target.id);
                    $addBtn.click()
                })
                var idType = null;
                var base5Arr = relationObj["base5Arr"];
                var base6Arr = relationObj["base6Arr"];
                if (base5Arr.length > 0) {
                    itemModel = base5Arr[0]
                    idType = self.checkIdType(itemModel.id + "");
                    if (idType != null) {
                        $("select[name=frontSuggestType]").val(idType);
                        if (idType == "simple-video") {
                            self.addMultipleItem(base5Arr, '#appendFront_' + idType, true);
                        } else {
                            self.addSingleItem(base5Arr, '#appendFront_' + idType);
                        }
                    }
                }
                if (base6Arr.length > 0) {
                    itemModel = base6Arr[0]
                    idType = self.checkIdType(itemModel.id + "")
                    if (idType != null) {
                        $("select[name=endSuggestType]").val(idType);
                        if (idType == "simple-video") {
                            self.addMultipleItem(base6Arr, '#appendEnd_' + idType, true);
                        } else {
                            self.addSingleItem(base6Arr, '#appendEnd_' + idType);
                        }
                    }
                }

                // init passport id ;
                self.initPassportId(passportData);
            },

            initPassportId: function (passportData) {
                $("input[name=uid_hidden]").val(passportData.uid);
                $("input[name=nickname_hidden]").val(passportData.nickname);
                $("select[name=passport_select]").val("option_" + passportData.key);
                $("input[name=passport_" + passportData.key + "]").val(passportData[passportData.key]);
            },
            addSingleItem: function (dataArr, regName) {
                if (dataArr.length > 0) {
                    dataArr[0].label = "" + dataArr[0].id;
                    $(regName).suggest("setValue", dataArr[0]);
                }
            },

            addMultipleItem: function (dataArr, regName, showKey) {
                showKey = showKey ? true : false;
                $.each(dataArr, function (index, target) {
                    if (showKey) {
                        target["$$autocompleteShowKey"] = target.id;
                    }
                    $(regName).suggest("addValue", target);
                })
            },

            checkIdType: function (idStr) {
                var endStr = idStr.substr(idStr.length - 2)
                switch (endStr) {
                    case "00":
                        return "simple-video";
                    case "01":
                        return "album";
                    case "02":
                        return "playlist";
                    default :
                        return null;
                }
            },

            queryForLvOne: function (params) {
                var self = this;
                var requestData = {url: EpgWeb.Constant.thirdUrl_category_first_list_url, type: "get", params: params, needCookie: true};
                var option = {
                    url: EpgWeb.urlConfig.redirect,
                    type: "post",
                    dataType: "json",
                    data: {"request": JSON.stringify(requestData), timeSign: new Date().getTime()},
                    success: function (data) {
                        $("#secTagZone").html("");
                        if (data != null && data.data != null && data.data.channelData != null) {
                            self.queryForLvSec(data.data)
                        } else {
                            $("#secTagZone").html("没有数据");
                        }
                    },
                    error: function (data) {
                        $("#secTagZone").html("数据加载失败");
                    }
                }
                $.ajax(option)
            },

            queryForLvSec: function (responseData) {
                var self = this;
                var params = null;
                var requestData = null;
                self.remoteCheck.doCheck(responseData.channelData, function (data) {
                    console.log("Program.RemoteCheck.doCheck queryForLvSec")
                    $("input[name$=sec_category]").bind("click", function (event) {
                        var $sec_curTarget = $(event.currentTarget);
                        if ($sec_curTarget.prop("checked") == true) {
                            self.queryForLvThird({channelId: $sec_curTarget.attr("data-channel-id"), id: $sec_curTarget.val(), liveDisplay: 1, liveUsed: 1 })
                            console.log("wait to add $third_curTarget")
                        } else {
                            $("#thirdTagZone input[data-pid=" + $sec_curTarget.val() + "]").parent().remove();
                            console.log("wait to remove $third_curTarget");
                            self.updateThirdTagDiv();
                        }
                    })
                    var programEntity = self.dao.getProgram();
                    if (programEntity != null && programEntity.category != null) {
                        var toParent = $("#secTagZone");
                        $.each(programEntity.categoryArr, function (i, element) {
                            if (element.level == 2) {
                                toParent.find("input[value=" + element.id + "]").click();
                            }
                        })
                    }

                }, function startHandler(saveData) {

                    $.each(saveData, function (i, element) {
                        params = {channelId: responseData.channelId, id: element.categoryId, liveDisplay: 1, liveUsed: 1 };
                        requestData = {url: EpgWeb.Constant.thirdUrl_category_child_list_url, type: "get", params: params, needCookie: true};
                        $.ajax({
                            url: EpgWeb.urlConfig.redirect,
                            type: "post",
                            dataType: "json",
                            data: {"request": JSON.stringify(requestData), timeSign: new Date().getTime()},
                            success: function (data) {
                                element.complete = true;
                                if (data == null || data.length == 0) {
                                    console.log("queryForLvSec 没有获得数据");
                                    return;
                                }
                                if (data.length > 0) {
                                    var toParent = $("#secTagZone");
                                    $.each(data, function (i, element) {
                                        $('<label style="display: inline;margin-left: 5px"><input type="checkbox" data-channel-id="' + params.channelId + '" name="sec_category" data-name="' + element.name + '" value="' + element.id + '">' + element.name + '</label>').appendTo(toParent)
                                    });
                                }
                            },
                            error: function (data) {
                                element.complete = true;
                                console.log("queryForLvSec error")
                            }
                        })

                    });
                });
            },

            updateThirdTagDiv: function () {
                var hasThirdCategory = $("input[name=third_category]");
                if (hasThirdCategory.length > 0) {
                    $("#thirdTagDiv").show();
                } else {
                    $("#thirdTagDiv").hide();
                }
            },

            queryForLvThird: function (params) {
                var self = this;
                console.log("Program.RemoteCheck.doCheck queryForLvThird")
                var requestData = {url: EpgWeb.Constant.thirdUrl_category_child_list_url, type: "get", params: params, needCookie: true};
                var programEntity = self.dao.getProgram();
                var options = {
                    url: EpgWeb.urlConfig.redirect,
                    type: "post",
                    dataType: "json",
                    data: {"request": JSON.stringify(requestData), timeSign: new Date().getTime()},
                    success: function (data) {
                        if (data == null || data.length == 0) {
                            console.log(" queryForLvThird 没有获得数据");
                        } else {
                            var htmlArr = [];
                            var toParent = $("#thirdTagZone");
                            $.each(data, function (i, element) {
                                $('<label style="display: inline;margin-left: 5px"><input type="checkbox" data-name="' + element.name + '" data-pid="' + element.pid + '" name="third_category" value="' + element.id + '">' + element.name + '</label>').appendTo(toParent);
                            });
                            if (programEntity != null && programEntity.category != null) {
                                $.each(programEntity.categoryArr, function (i, element) {
                                    if (element.level == 3) {
                                        toParent.find("input[value=" + element.id + "]").prop("checked", true);
                                    }
                                })
                            }
                        }
                        self.updateThirdTagDiv();
                    },
                    error: function (data) {
                        if (data == null) {
                            console.log("queryForLvThird 没有获得数据 error");
                            return;
                        }
                    }
                }
                $.ajax(options);
            }


        })
    }
);